package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-03-12 00:28
 */
public class IsValidSerialization {

    int i = -1;
    int length = 0;

    public boolean isValidSerialization(String preorder) {
        String[] node = preorder.split(",");
        length = node.length;
        dfs(node);
        return i == node.length - 1;
    }

    private void dfs(String[] node) {
        i++;
        if (i>=length) return;
        if (node[i].equals("#")) return;
        dfs(node);
        dfs(node);
    }

    public static void main(String[] args) {
        new IsValidSerialization().isValidSerialization("1");
    }
}
